package top.anonyeast.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.anonyeast.dao.UserDao;
import top.anonyeast.pojo.User;

import javax.annotation.Resource;

@RestController("userController")
@RequestMapping("/user")
public class UserController {
    @Resource(name = "userDao")
    private UserDao dao;
    @Resource(name = "user")
    private User user;

    @PostMapping("/getUserCount")
    public Long getUserCount(String username){
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("username",username);
        return dao.selectCount(wrapper);
    }

    @PostMapping("/signup")
    public boolean signup(User user) {
        if (user.checkUserIsValid(user)){
            int insert_count = dao.insert(user);
            return insert_count > 0;
        }
        return false;
    }


}
